package lc;

import java.awt.Point;
import java.util.HashMap;
import java.util.Map;

public class MaxPointsOnLine {
    public int maxPoints(Point[] points) {
    	HashMap<Integer, HashMap<Integer, Integer>> lines = new HashMap<>();
    	for (int i=0; i<points.length-1; i++) {
    		Point pi = points[i];
    		for (int j=i+1; j<points.length; j++) {
    			Point pj = points[j];
    			int k = (pj.y - pi.y) / (pj.x - pi.x);
    			if (!lines.containsKey(k)) {
    				lines.put(k, new HashMap<Integer, Integer>());
    			}
    			HashMap<Integer,Integer> map = lines.get(k);
    			int b = (pj.x*pi.y - pi.x*pj.y) / (pj.x - pi.x);
    			if (!map.containsKey(b)) {
    				map.put(b, 0);
    			}
    			Integer count = map.get(b);
				map.put(b, count+1);
    		}
    	}
    	int max=0;
    	for (Map.Entry<Integer, HashMap<Integer, Integer>> samek : lines.entrySet()) {
    		for (Map.Entry<Integer, Integer> sameb : samek.getValue().entrySet()) {
    			if (sameb.getValue() > max) {
    				max = sameb.getValue();
    			}
    		}
    	}
    	return max;
    }

}
